﻿Imports TMySQL
Imports System.Windows.Forms.DataVisualization.Charting

Public Class frmProfile
    Implements ITabForm

    Private MyProfileList As TMyProfileList

    Public Sub New()
        ' この呼び出しは、Windows フォーム デザイナで必要です。
        InitializeComponent()
        ' InitializeComponent() 呼び出しの後で初期化を追加します。
        MyProfileList = frmMain.ProfileList
        InitFrm()
    End Sub

    Private Sub InitFrm()
        frmMain.GeneralSettings.ApplyAll(Me)
        frmMain.EditorSettings.ApplyAll(Me)
        frmMain.GridSettings.ApplyAll(Me)
    End Sub

    Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
        Cursor.Current = Cursors.WaitCursor
        Try
            ShowProfile()
        Finally
            Cursor.Current = Cursors.Default
        End Try
    End Sub

    Private Sub ShowProfile()
        MyProfileList.Refresh()
        lv.Items.Clear()
        For i As Integer = 0 To MyProfileList.Count - 1
            Dim item As New ListViewItem(MyProfileList(i).ID.ToString)
            item.SubItems.Add(MyProfileList(i).Duration.ToString)
            lv.Items.Add(item)
        Next
        For Each col As ColumnHeader In lv.Columns
            col.Width = -2
        Next
    End Sub

    Private Sub ShowDetail(ByVal AIndex As Integer)
        Grid.DataSource = MyProfileList.GetDetail(AIndex)
        Common.SetGridAllowSorting(Grid, DataGridViewColumnSortMode.NotSortable)
        ShowBarGraph()
    End Sub

    Private Sub lv_ItemSelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles lv.ItemSelectionChanged
        txtSQL.Text = String.Empty
        Grid.DataSource = Nothing
        If Not e.IsSelected Then
            Return
        End If
        Cursor.Current = Cursors.WaitCursor
        Try
            txtSQL.Text = MyProfileList(e.ItemIndex).SQL
            ShowDetail(e.ItemIndex)
        Finally
            Cursor.Current = Cursors.Default
        End Try
    End Sub


    Private Sub ShowBarGraph()

    End Sub
End Class